<?php
require_once('TVB/PWORKS/mvc/IAction.iface.php');
require_once('TVB/PWORKS/message/Messager.class.php');

abstract class BaseAction implements IAction {
    protected $_errors;
	protected $_warnings;
	protected $_infos;
	protected $_data;
//    protected $_voBind;
    protected $_config;

	//------------------------------------------
	//[Jul. 23, 2009][Milo]
	//Add property "result" and related functions
	protected $____result____;

	public function setResult($result){
		$this->____result____ = $result;
	}

	public function getResult(){
		return $this->____result____;
	}

	/** 
	 * append by Vanni start///////////
	 */
    public function getPermissionItems(){
		return permission::getPermssionNamesByActionObj($this);
	}
	///////////////////end/////////////

    public function fillData($dataType){
      foreach($this as $key => $value) {
          $this->$key = FrontController::getDataHelper()->get($key, $dataType);
      }
	}
	
	public function setData($key, $value){
	    $this->_data[$key] = $value;
	}
	
	public function getData(){
		return $this->_data; 
	}

	public function removeData($key)
	{
		unset($this->_data[$key]);
	}

	public function emptyData()
	{
		$data = $this->getData();
		foreach ($data as $key=>$value)
		{
			$this->removeData($key);
		}
	}
	
	public function getErrors() {
		return $this->_errors;
	}

	public function getWarnings() {
		return $this->_warnings;
	}
	
    public function getInfos(){
	    return $this->_infos;
	}
	
	public function addError($fieldId, $content, $details=array()){
	    $message = new Message();
	    $message->type = Message::TYPE_ERROR;
	    $message->ownerId = $fieldId;
	    $message->content = $content;
	    $message->details = $details;
	    $this->_errors[$fieldId][] = $message; 
	}
	
    public function addWarning($fieldId, $content, $details=array()){
	    $message = new Message();
	    $message->type = Message::TYPE_WARNING;
	    $message->ownerId = $fieldId;
	    $message->content = $content;
	    $message->details = $details;
	    $this->_warnings[$fieldId][] = $message;
	}
	
	public function addInfo($fieldId, $content, $details=array()){
	    $message = new Message();
	    $message->type = Message::TYPE_NORMAL;
	    $message->ownerId = $fieldId;
	    $message->content = $content;
	    $message->details = $details;
	    $this->_infos[$fieldId][] = $message;
	}
	
	public function setConfig(ActionConfig $config){
	    $this->_config = $config;
	}
	
	public function getConfig(){
	    return $this->_config;
	}
}
?>
